﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KZ.Express.H.Presenter;
using KZ.Express.H.ENT;
using KZ.Utilities;

namespace KZ.Express.H.Orders
{
    public partial class OrderLogListView : BaseView
    {
        private void OrderLogListView_Load(object sender, EventArgs e)
        {
            dtpFrom.Value = DateTime.Today.AddDays(-7);
            dtpTo.Value = DateTime.Today;
        }

        private void dtgLog_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != -1 && e.RowIndex != -1)
            {
                OrderLogDetailView view = new OrderLogDetailView();
                view.ActionName = "Exit";
                view.EntityID = Utility.IntParse(dtgLog[colLogID.Index, e.RowIndex].Value);

                MainView mainView = Application.OpenForms["MainView"] as MainView;
                mainView.OpenTab(view);
            }
        }

        public OrderLogListView()
        {
            InitializeComponent();
            Initialize(dtgLog);

            _presenter = new BasePresenter(this);

            this.ObjectID = (int)Objects.Logs;
            //this.ActionName = "List";
            this.VisibleChanged += new EventHandler(View_VisibleChanged<LogENT>);
            this.dtgLog.Sorted += new EventHandler(Datagrid_Sorted);
            this.btnSearch.Click += new EventHandler(View_OnSearchClick<LogENT>);
            this.btnViewAll.Click += new EventHandler(View_OnViewAllClick<LogENT>);
        }

        #region Public Properties

        [Search]
        public DateTime From
        {
            get { return dtpFrom.Value; }
            set
            {
                if (value != DateTime.MinValue)
                    dtpFrom.Value = value;
            }
        }

        [Search]
        public DateTime To
        {
            get { return dtpTo.Value; }
            set
            {
                if (value != DateTime.MinValue)
                    dtpTo.Value = value;
            }
        }

        [Search]
        public string FullName
        {
            get { return txtFullName.Text; }
            set { txtFullName.Text = value; }
        }

        [Search]
        public string Description
        {
            get { return txtDescription.Text; }
            set { txtDescription.Text = value; }
        }

        #endregion
    }
}
